package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtCouponPrivateUserBound;
import com.ymttest.utils.EnvSetup;

public class YmtCouponPrivateUserBoundWapper {
	SqlManager manager;
	
	public YmtCouponPrivateUserBoundWapper() {
		manager = new SqlManager("ymt" + EnvSetup.getEnv());
	}
	
	public List<YmtCouponPrivateUserBound> selectBysCouponCode(String sCouponCode) {
		List<YmtCouponPrivateUserBound> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.YmtCouponPrivateUserBoundMapper.selectBysCouponCode",
						sCouponCode);
		return result;
	}
	
	public List<YmtCouponPrivateUserBound> selectBysCouponId(String sCouponId) {
		List<YmtCouponPrivateUserBound> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.YmtCouponPrivateUserBoundMapper.selectBysCouponId",
						sCouponId);
		return result;
	}
	
	public YmtCouponPrivateUserBound selectTop1() {
		YmtCouponPrivateUserBound result = (YmtCouponPrivateUserBound) manager
				.getSelectResults(
						"com.ymttest.database.mapping.YmtCouponPrivateUserBoundMapper.selectTop1",null).get(0);
		return result;
	}
	
	public List<YmtCouponPrivateUserBound> selectTop5() {
		List<YmtCouponPrivateUserBound> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.YmtCouponPrivateUserBoundMapper.selectTop5",null);
		return result;
	}
	
	public void UpdateiCouponUsedCount(String couponCode, int num) {
		Map m = new HashMap();
		m.put("couponCode", couponCode);
		m.put("num", num);
		manager.update(
						"com.ymttest.database.mapping.YmtCouponPrivateUserBoundMapper.UpdateiCouponUsedCount", m);
		manager.commit();
	}
	
	public List<YmtCouponPrivateUserBound> selectByBatchIdAndUserId(int iBatchId, int iUserId) {
		Map m = new HashMap();
		m.put("iBatchId", iBatchId);
		m.put("iUserId", iUserId);
		
		List<YmtCouponPrivateUserBound> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.YmtCouponPrivateUserBoundMapper.selectByBatchIdAndUserId",
						m);
		return result;
	}
}
